import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'

import { createRouter, createWebHistory } from 'vue-router'

const UserLayout = () => import('@/user-layout/layout.vue')
// const Authentication = () => import('@/pages/authentication/index.vue')

export const constantRouterMap: AppRouteRecordRaw[] = [
    {
        children: [
           
            {
                component: () => import('@/pages/my-contract/index.vue'),
                meta: {
                    // title: '首页-home',
                    title: '我的合同',
                },
                name: 'root-index',
                path: '/',
                redirect: '/my-contract',
                children: [
                    {
                        component: () => import('@/pages/my-contract/list.vue'),
                        meta: {
                            title: '我的合同',
                        },
                        name: 'my-contract',
                        path: '/my-contract',
                    },
                    {
              
                        component: () => import('@/pages/my-contract/demo1/index.vue'),
                        meta: {
                            hidden: true,
                            noTagsView: true,
                            title: 'demo1',
                        },
                        name: 'demo1',
                        path: '/demo1',
                    },
                    {
                      
                        component: () => import('@/pages/my-contract/demo2/index.vue'),
                        meta: {
                            hidden: true,
                            noTagsView: true,
                            title: 'demo2',
                        },
                        name: 'demo2',
                        path: '/demo2',
                    },
                ]

            },

        ],
        component: UserLayout,
        meta: {
            hidden: true,
            noTagsView: true,
            title: '首页',
        },
        name: 'root',
        path: '/',
    },

    {
        children: [
            {
                component: () => import('@fl/views/redirect/redirect.vue'),
                meta: {},
                name: 'Redirect',
                path: '/redirect/:path(.*)',
            },

            {
                component: () => import('@fl/views/error/404.vue'),
                meta: {
                    hidden: true,
                    noTagsView: true,
                    title: '404',
                },
                name: 'NoFind',
                path: '/404',
            },
        ],
        component: UserLayout,
        meta: {
            hidden: true,
            noTagsView: true,
        },
        name: 'Redirect',
        path: '/redirect',
    },
    {
        component: () => import('@/pages/login/index.vue'),
        meta: {
            hidden: true,
            noTagsView: true,
            title: '登录',
        },
        name: 'login',
        path: '/login',
    },

    // {
    //     component: () => import('@/pages/register/register.vue'),
    //     meta: {
    //         hidden: true,
    //         noTagsView: true,
    //         title: '注册',
    //     },
    //     name: 'register',
    //     path: '/register',
    // },
    // {
    //     component: () => import('@/pages/forget-password/forget-password.vue'),
    //     meta: {
    //         hidden: true,
    //         noTagsView: true,
    //         title: '忘记密码',
    //     },
    //     name: 'forget-password',
    //     path: '/forget-password',
    // },

]

export const asyncRouterMap: AppRouteRecordRaw[] = []
const router = createRouter({
    history: createWebHistory(),
    routes: constantRouterMap as RouteRecordRaw[],
    scrollBehavior: () => ({ left: 0, top: 0 }),
    strict: true,
})

export function resetRouter(): void {
    const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
    router.getRoutes().forEach((route) => {
        const { name } = route
        if (name && !resetWhiteNameList.includes(name as string))
            router.hasRoute(name) && router.removeRoute(name)
    })
}

export function setupRouter(app: App<Element>) {
    app.use(router)
}

export default router
